package com.credithc.fastdfs.monitor.util;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import org.apache.commons.io.IOUtils;

import com.credithc.framework.core.utils.AESUtils;

public class HttpUtils {
	public static final String AES_UUC_KEY="DtbW9aZurnFg3ZiP";
	
	public static String httpInteface(String interfaceUrl, StringBuffer parm) {
		String result = "false";
		try {
			// 需要请求的restful地址
			URL url = new URL(interfaceUrl);
			// 打开restful链接	
			HttpURLConnection conn = (HttpURLConnection) url.openConnection();
			// 提交模式
			conn.setRequestMethod("POST");// POST GET PUT DELETE
			// 设置访问提交模式，表单提交
			conn.setRequestProperty("Content-Type",
					"application/x-www-form-urlencoded");
			conn.setConnectTimeout(1000000);// 连接超时 单位毫秒
			conn.setReadTimeout(200000000);// 读取超时 单位毫秒
			conn.setDoOutput(true);// 是否输入参数
			// 表单参数与get形式一样
			byte[] bypes = parm.toString().getBytes();
			conn.getOutputStream().write(bypes);// 输入参数
			InputStream inStream = conn.getInputStream();
			result = IOUtils.toString(inStream, "UTF-8");
			inStream.close();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			return result;
		}
	}
	
	public static String httpIntefaceDesc(String interfaceUrl, StringBuffer parm) {
		String result = httpInteface(interfaceUrl,parm);
		return AESUtils.AES_Decrypt(AES_UUC_KEY,result);
	}

}
																																																																																																																